package com.ysd.lis.service.emr.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.emr.EmrGrade;
import com.ysd.lis.mapper.emr.EmrGradeMapper;
import com.ysd.lis.service.emr.EmrGradeService;
import jar.org.apache.pdfbox.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author whx
 * @since 2025-06-04
 */
@Service
public class EmrGradeServiceImpl extends ServiceImpl<EmrGradeMapper, EmrGrade> implements EmrGradeService {

    @Autowired
    private EmrGradeMapper emrGradeMapper;

    @Override
    public Result editEmrGrade(EmrGrade emrGrade) {
        int i = emrGradeMapper.updateById(emrGrade);
        if (i > 0) {
            return Result.succ(1, "编辑成功！", emrGrade);
        } else {
            return Result.fail("编辑失败！");
        }

    }

    @Override
    public Result findEmrGradeList(EmrGrade emrGrade) {
        LambdaQueryWrapper<EmrGrade> lambdaQueryWrapper = new LambdaQueryWrapper();
        if (!StringUtils.isEmpty(emrGrade.getGradeName())){
            lambdaQueryWrapper.and(wrapper -> wrapper.like(EmrGrade::getGradeName, emrGrade.getGradeName()).or().like(EmrGrade::getGradeCode, emrGrade.getGradeName()));
        }
        lambdaQueryWrapper.eq(EmrGrade::getDelFlag, 0);
        List<EmrGrade> emrGradeList = emrGradeMapper.selectList(lambdaQueryWrapper);
        return Result.succ(1,"获取信息成功",emrGradeList);
    }

    @Override
    public Result addEmrGrade(EmrGrade emrGrade) {
        int insert = emrGradeMapper.insert(emrGrade);
        if (insert > 0) {
            return Result.succ(1, "添加成功", emrGrade);
        } else {
            return Result.fail(400, "添加失败", "");
        }
    }
}
